<template slot-scope="scope">
    <div>
        <van-nav-bar title="面经"/>
        <van-form >
            <van-field
            label="用户名"
            placeholder="请输入用户名"
            v-model="username"
            ></van-field>
            <van-field
            label="密码"
            placeholder="请输入密码"
            type="password"
            v-model="password"
            ></van-field>
        <div style="margin:16px">
            <van-button type="primary" block @click="onSubmit()">注册</van-button>
        </div>
    </van-form>


    </div>
</template>

<script>
import {register} from '@/api/user'
export default{
    data(){
        return{
            username:'',
            password:''
        }
    },
    methods:{
      async  onSubmit(){
//消息提示
        this.$toast.loading({
            message:'正在拼命的加载中.....',
            forbidClick:true//禁止点击页面背景元素
        })
            try{
                //注册成功跳转到登录页面
                await register({username:this.username,password:this.password})
                this.$toast.success("注册成功")
                this.$router.push('login')
            }catch{
                // 提示注册失败
                this.$toast.fail("注册失败")
            }
        


        }
    }
}
</script>
<!-- scoped防止溢出影响其他页面 -->
<style scoped lang="less">
.link{
    float: right;
    padding-right: 20px;
    font-size:10px
}
</style>